<?php
/**
 * welcome developer.
 * author: liangbo
 * company:tencent suzhou
 * contact:173120209
 * mobile:18550451730
 * Date: 2016-12-19
 * Time: 15:44
 */
//生成model的类
class load {


  function __construct()
  {


    $this->tablelist();

    $this->load="include(";


  }


//获取数据库的表
  function tablelist()
  {

      $table=(new Model)->query('show tables')->fetchAll();

      if(!empty($table))
      {
        $model=array();
        foreach($table as $k=>$v)
        {

         $model[$k]=$v[0];

        }
          if(!empty($model))
          {
             foreach($model as $k1=>$v1)
             {

                 $this->model_create($v1);


             }

          }
      }

  }

//生成model
    function  model_create($model)
    {
          if(strstr($model,prefix))
          {
              $model=str_replace(prefix,'',$model);
              $model=ucfirst($model);
              $modelname=APP_PATH.'application/models/'.$model.'Model.php';
              if(!file_exists($modelname))
              {
                  $contents=$this->model_content($model);
                  foreach($contents as $k=>$v)
                  {

                      file_put_contents($modelname,$v.PHP_EOL,FILE_APPEND);

                  }

              }
          }

    }


//model模板
    function  model_content($model)
    {


        $classname=$model.'Model';
        return $contents=array(
            '<?php',
            '/**',
            '* welcome developer.',
            '* author: liangbo',
            '* contact:173120209',
            '* mobile:18550451730',
            '* Date: '.date('Y-m-d').'',
            '* Time: '.date('h:i').'',
            '*/',
            '',
            'class '.$classname.' extends Model {',
            '//model封装方法查找',
            '   function find($join, $columns=null, $where=null)',
            '    {',
            '        return $this->select($this->_table,$join, $columns, $where);',
            '    }',
            '',
            '//model封装方法增加',
            '',
            '   function add($data)',
            '    {',
            '       return $this->insert($this->_table,$data);',
            '    }',
            '',
            '//model封装方法更新',
            '',
            '   function upp($data,$where)',
            '    {',
            '      return $this->update($this->_table,$data,$where);',
            '    }',
            '',
            '//model封装方法删除',
            '',
            '   function del($where)',
            '    {',
            '      return $this->delete($this->_table,$where);',
            '    }',
            '',
            '}',

            );





    }





























}